Lexicographic breadth-first search